<!--  -->
<template>
  <div class="app-container">
    <div class="filter-container">
            <el-input placeholder="请输入用户ID" v-model="listQuery.userId" clearable class="search-item"></el-input>
            <el-input placeholder="请输入收货人名称" v-model="listQuery.name" clearable class="search-item"></el-input>
            <el-button  type="primary" :loading="searchLoading" icon="el-icon-search" @click="handleFilter">查找</el-button>
        </div>
        <el-table
        :data="tableData"
        style="width: 100%"
        border 
        :header-cell-style="{'text-align':'center'}"
        :default-sort = "{prop: 'id', order: 'descending'}" :cell-style="{ 'text-align': 'center' }"
        >
        <el-table-column
          prop="id"
          label="地址ID"
          sortable
          width="180">
        </el-table-column>
        <el-table-column
          prop="userId"
          label="用户ID"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          label="收货人名称">
        </el-table-column>
        <el-table-column
          prop="tel"
          label="手机号码">
        </el-table-column>
        <el-table-column
          prop="province"
          label="区域地址">
          <template slot-scope="scope">
            {{scope.row.province+scope.row.city+scope.row.county}}
          </template>
        </el-table-column>
        <el-table-column
          prop="addressDetail"
          label="详细地址">
        </el-table-column>
        <el-table-column
          prop="isDefault"
          label="默认">
          <template slot-scope="scope">
            {{scope.row.isDefault?'是':'否'}}
          </template>
        </el-table-column>
        </el-table>
        <div class="footerPage">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20]"
      :page-size="listQuery.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
  </div>
</template>
<script >
import { listAddress} from '@/api/address/address'
export default {
    name:'UserAddress',
    data() {
      return{
        listQuery: {
          page:1,
          limit:2,
          userId:'',
          name:'',
          sort: 'add_time',
          order: 'desc'
        },
        total:0,
        currentPage:'',
        searchLoading:false,
        tableData:[],
      }
    },
    props:[],
    components: {},
    created() {
        this.getList();
    },
    mounted() {
    },
    methods:{
        handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.listQuery.page = 1;
        this.getList();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.listQuery.page = val;
        this.getList();
      },
      getList(){
        listAddress(this.listQuery).then(res => {
          console.log(res);
          this.tableData = [];
          this.tableData = res.data.data.list;
          this.total = res.data.data.total;
        })
      },
      handleFilter(){
        this.listQuery.page = 1;
        this.getList();
      }
    }
  };
</script>
<style scoped>
.app-container {
        width: 98%;
        height: 100%;
        margin: auto
    }
    .filter-container{
        display: flex;
        justify-content: right;
        align-items: center;
    }
    .footerPage{
      margin-top: 20px;
      float: right;
    }
</style>
<style lang='scss'>
.search-item{
      width: 200px;
      margin-right: 5px;
    }
</style>